package com.haoyun.mirage.user.model.vo;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.collect.Lists;
import com.haoyun.common.constant.SecurityConstants;
import com.haoyun.common.core.jackson.serializer.LongJsonDeserializer;
import com.haoyun.common.core.jackson.serializer.LongJsonSerializer;
import com.xiaoleilu.hutool.collection.CollectionUtil;
import com.xiaoleilu.hutool.util.StrUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

/**
 * Created by twg on 2018/6/3.
 */
@Data
public class UserVO implements Serializable {

    private static final long serialVersionUID = 6151491293299693607L;

    @JsonSerialize(using = LongJsonSerializer.class)
    @JsonDeserialize(using = LongJsonDeserializer.class)
    private Long id;
    @JsonSerialize(using = LongJsonSerializer.class)
    @JsonDeserialize(using = LongJsonDeserializer.class)
    private Long compId;//公司ID
    @JsonSerialize(using = LongJsonSerializer.class)
    @JsonDeserialize(using = LongJsonDeserializer.class)
    private Long deptId;//部门ID
    private String deptName;
    private String userName;
    private String realName;
    private Integer userLevel;//用户级别
    private String salt;
    private String userPassword;

    private Set<RoleVO> rolesSet;

    /**
     * 角色id集合
     */
    private String[] roleIds;


    /**
     * 权限标识集合
     */
    private String[] permissions;

    public String[] getRoles() {
        List<String> roleCodes = Lists.newArrayList();
        if (CollectionUtil.isNotEmpty(rolesSet)) {
            for (RoleVO roleVO : rolesSet) {
                if (!StrUtil.equals(SecurityConstants.BASE_ROLE, roleVO.getRoleCode())) {
                    roleCodes.add(roleVO.getRoleCode());
                }
            }
        }
        return roleCodes.toArray(new String[roleCodes.size()]);
    }
}
